import * as tslib_1 from "tslib";
import { observable, action } from 'mobx';
export let LoadHoc = class LoadHoc {
  constructor() {
    this.loadingCode = 0;
    this.loadingStatus = {};
  }
  setLoading(key) {
    this.loadingStatus[key] = true;
    this.loadingCode++;
    this.loading = this.loadingCode > 0;
  }
  setLoaded(key) {
    this.loadingStatus[key] = false;
    this.loadingCode--;
    this.loading = this.loadingCode > 0;
  }
};
tslib_1.__decorate([observable], LoadHoc.prototype, "loading", undefined);
tslib_1.__decorate([observable], LoadHoc.prototype, "loadingStatus", undefined);
tslib_1.__decorate([action.bound], LoadHoc.prototype, "setLoading", null);
tslib_1.__decorate([action.bound], LoadHoc.prototype, "setLoaded", null);
export const loading = (target, key, descriptor) => {
  let method = descriptor.value;
  descriptor.value = async function () {
    this.setLoading(key);
    const result = await method.apply(this, arguments);
    this.setLoaded(key);
    return result;
  };
};